from django.contrib.contenttypes.fields import GenericRelation
from django.db import models
from django.shortcuts import reverse
from django.utils.translation import gettext_lazy as _
from audit.models import AuditManagement
from lib.django import models as mymodels
from .project import Project
from lib.django import models as mymodels

from .lib import ProjectSubMixin

class BeforeImplement(ProjectSubMixin, models.Model):
    project = models.OneToOneField(
        verbose_name=_("项目"),
        to=Project,
        on_delete=models.CASCADE,
    )
    
    is_materials_complete = mymodels.YesNoField(
        verbose_name=_('物资、药品是否完备'), 
        default=False
    )
    
    is_confirmed_by_manager = mymodels.YesNoField(
        verbose_name=_('是否经机构物资管理人员确认'), 
        default=False
    )
    
    medicine_storage = models.CharField(
        verbose_name=_('药品储藏房间及柜号'), 
        max_length=255, 
        blank=True, 
        default='',
        help_text=_('名字之间可以用逗号')
    )
    
    specimen_storage = models.CharField(
        verbose_name=_('标本储藏房间及柜号'), 
        max_length=255, 
        blank=True, 
        default='',
        help_text=_('名字之间可以用逗号')
    )
    
    file_storage = models.TextField(
        verbose_name=_('文件储藏房间及柜号'), 
        blank=True,
        default='',
        help_text=_('研究期间中心文件夹及文件藏房间及柜号')
    )

    audit_management = GenericRelation(
        AuditManagement,
        content_type_field='content_type',
        object_id_field='object_id',
        verbose_name=_("审核管理")
    )


    class Meta:
        default_permissions = []
        db_table = 'project_before_implement'
        verbose_name = _('项目启动前')
        verbose_name_plural = verbose_name
        
    @classmethod
    def get_link(cls, project_id, id):
        return reverse("project:before_implement/detail", kwargs={'project_pk': project_id})
